home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 2002 Tom Parker (tom@carrott.org),
- Matthias Münch (matthias@amigaworld.de)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- In addition, as a special exception, Tom Parker and Matthias Münch give
- permission to link the code of this program with a TCP stack of your
- choice, any official MUI libraries or classes and any custom MUI classes
- that should be necessary for the operation of this program. This
- exception also gives you permission to distribute linked combinations
- including this software with any of the before-mentioned libraries and
- classes. You must obey the GNU General Public License in all respects for
- all of the code used other than that provided by the before-mentioned
- libraries and classes. As part of this exception you are obliged to
- follow the license terms of the before-mentioned libraries, this license
- does not compel you to follow those terms, but if you do not then you may
- not link with those libraries. If you modify this file, you may extend
- this exception to your version of the file, but you are not obligated to
- do so. If you do not wish to do so, delete this exception statement from
- your version.
- */
- /*
- ** search&result windows
- */
-
- #include "common.h"
-
- #include <MUI/NListview_mcc.h>
-
- static ULONG search_new(struct IClass *cl, Object *obj, struct opSet *msg);
- static ULONG search_result_new(struct IClass *cl, Object *obj, struct opSet *msg);
- static MUI_LIST_DISP2_DECL(result_disp);
-
-
- MUI_DISPATCH(search_dispatch)
- {
- switch(msg->MethodID)
- {
- case OM_NEW:
- return search_new(cl,obj,(APTR)msg);
-
- case SEARCH_GO:
- {
- struct searchdata *data = INST_DATA(cl,obj);
- iks *x;
-
- x = xmlform_print(data->xform);
- iks_insert_attrib(iks_find(x, "query"), "xmlns", IKS_NS_SEARCH);
- iks_send(net.parser, x);
- iks_delete(x);
- DoMethod(gui.app, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
- return 0;
- }
-
- }
- return DoSuperMethodA(cl,obj,msg);
- }
-
-
- static ULONG search_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- struct searchdata *data;
- ikspak *pak;
- Object *xform, *searchbut, *canbut;
-
- pak = (ikspak *)GetTagData(SEARCH_PACKET, NULL, msg->ops_AttrList);
- if(!pak) return(NULL);
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_HelpNode, "window-search",
- WindowContents, VGroup,
- Child, xform = xmlform_create(pak),
- Child, RectangleObject,
- MUIA_FixHeightTxt, "M",
- MUIA_Rectangle_HBar, TRUE,
- End,
- Child, HGroup,
- Child, searchbut = mui_button(MSG_SEARCH_GO_GAD),
- Child, canbut = mui_button(MSG_SEARCH_CANCEL_GAD),
- End,
- End,
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj) return(0);
-
- data = INST_DATA(cl,obj);
- data->xform = xform;
- data->pak = pak;
-
- DoMethod(searchbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, SEARCH_GO);
-
- DoMethod(canbut, MUIM_Notify, MUIA_Pressed, FALSE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
-
- return (ULONG)obj;
- }
-
-
- MUI_DISPATCH(search_result_dispatch)
- {
- switch(msg->MethodID)
- {
- case OM_NEW:
- return search_result_new(cl,obj,(APTR)msg);
-
- case SEARCH_ADD:
- {
- iks *x;
- struct searchresultdata *data = INST_DATA(cl,obj);
- DoMethod(data->list, MUIM_NList_GetEntry, MUIV_NList_GetEntry_Active, &x);
- if(!x) return(0);
- contact_ask(iks_find_attrib(x, "jid"), iks_find_cdata(x, "nick"));
- return 0;
- }
-
- }
- return DoSuperMethodA(cl,obj,msg);
- }
-
-
- static ULONG search_result_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- static struct Hook dispHook = { {0,0}, &result_disp, NULL, NULL };
- struct searchresultdata *data;
- Object *list, *addbut, *canbut;
- ikspak *pak;
- iks *y;
- int cnt = 0, i = 0;
- char *lala;
-
- pak = (ikspak *)GetTagData(SEARCH_PACKET, NULL, msg->ops_AttrList);
- if(!pak) return(NULL);
-
- y = iks_child(iks_find(iks_find(pak->x, "query"), "item"));
- if(!y) return(NULL);
- while(y)
- {
- if(iks_type(y) == IKS_TAG) cnt++;
- y = iks_next(y);
- }
- cnt++;
- lala = malloc((cnt*5) + 2);
- while(cnt)
- {
- strcpy(lala + i, "BAR,");
- i += 4;
- cnt--;
- }
- lala[i] = '\0';
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_Window_Title, "Search Results",
- MUIA_HelpNode, "window-searchresult",
- WindowContents, VGroup,
- Child, NListviewObject,
- MUIA_NListview_NList, (ULONG) list = NListObject,
- InputListFrame,
- MUIA_NList_Title, TRUE,
- MUIA_NList_Format, lala,
- MUIA_NList_DisplayHook2, &dispHook,
- MUIA_CycleChain, 1,
- End,
- End,
- Child, HGroup,
- Child, addbut = mui_button(MSG_SEARCH_ADD_GAD),
- Child, canbut = mui_button(MSG_SEARCH_CANCEL_GAD),
- End,
- End,
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj) return(0);
-
- data = INST_DATA(cl,obj);
- data->list = list;
- data->pak = pak;
-
- y = iks_child(iks_find(pak->x, "query"));
- set(list, MUIA_NList_PrivateData, (ULONG) y);
- while(y)
- {
- if(iks_type(y) == IKS_TAG)
- DoMethod(list, MUIM_NList_InsertSingle, y, MUIV_NList_Insert_Bottom);
- y = iks_next(y);
- }
-
-
-
- DoMethod(addbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, SEARCH_ADD);
-
- DoMethod(canbut, MUIM_Notify, MUIA_Pressed, FALSE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
-
- return((ULONG)obj);
- }
-
-
- MUI_LIST_DISP2_STATIC(result_disp)
- {
- iks *x = msg->entry;
- int i = 0;
-
- if(x)
- {
- msg->strings[i++] = iks_find_attrib(x, "jid");
- x = iks_child(x);
- while(x)
- {
- if(iks_type(x) == IKS_TAG)
- msg->strings[i++] = iks_cdata(iks_child(x));
-
- x = iks_next(x);
- }
- }
- else
- {
- get(obj, MUIA_NList_PrivateData, &x);
- msg->strings[i++] = "Jabber ID";
- while(x)
- {
- if(iks_type(x) == IKS_TAG)
- msg->strings[i++] = iks_name(x);
-
- x = iks_next(x);
- }
- }
-
- return 0;
- }
-
-
- void search_display(ikspak *pak)
- {
- Object *win;
- iks *x;
-
- if(pak->subtype != IKS_TYPE_RESULT) return;
- x = iks_child(iks_find(pak->x, "query"));
- if(!x) return;
-
- if(iks_strcmp(iks_name(x), "item") == 0)
- win = NewObject(gui.search_result_mcc->mcc_Class, NULL, SEARCH_PACKET, (ULONG) pak, TAG_DONE);
- else
- win = NewObject(gui.search_mcc->mcc_Class, NULL, SEARCH_PACKET, (ULONG) pak, TAG_DONE);
-
- if(win)
- {
- DoMethod(gui.app, OM_ADDMEMBER, win);
- set(win, MUIA_Window_Open, TRUE);
- }
- }
-